//
//  CouponTableViewCell.m
//  TerritoryShopkeeper
//
//  Created by 李小龙 on 2017/12/4.
//  Copyright © 2017年 ZDQK. All rights reserved.
//

#import "CouponTableViewCell.h"

@interface CouponTableViewCell ()
{
    NSInteger _type;
}
@end

@implementation CouponTableViewCell

- (IBAction)exchangeButtonAction:(id)sender {
    if (self.block) {
        self.block();
    }
}

+ (instancetype)couponTableCellWith:(UITableView *)tableView type:(NSInteger)type {
    NSString *identifier = @"couponTableIdentifier";
    NSInteger index = 0;
    CouponTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"CouponTableViewCell" owner:self options:nil] objectAtIndex:index];
    }
    return cell;
}

- (void)updateCellWith:(CouponModel *)model type:(NSInteger)type {
    _type = type;
    switch (type) {
        case 0:
        {
            // 可领取
            NSString *str = [NSString stringWithFormat:@"%@积分",model.mcintegral];
            NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:str];
            [attributeStr setAttributes:@{NSFontAttributeName:TextPingFangMediumFontSize(20),
                                          NSForegroundColorAttributeName:[UIColor ThemeColor]
                                          } range:NSMakeRange(0, str.length-2)];
            [attributeStr setAttributes:@{NSFontAttributeName:TextPingFangFontSize(10),
                                          NSForegroundColorAttributeName:[UIColor ThemeColor]
                                          } range:[str rangeOfString:@"积分"]];
            [self.statusLabel setAttributedText:attributeStr];
            
            [self.exchangeButton setHidden:NO];
        } break;
        case 1:
        {
            // 未使用
            [self.statusLabel setTextColor:[UIColor ThemeColor]];
            [self.statusLabel setFont:TextPingFangFontSize(14)];
            [self.statusLabel setText:@"可使用"];
            
            [self.exchangeButton setHidden:YES];
        } break;
        case 2:
        {
            // 使用记录
            [self.statusLabel setTextColor:[UIColor grayTextColor]];
            [self.statusLabel setFont:TextPingFangFontSize(14)];
            [self.statusLabel setText:@"已使用"];
            
            [self.exchangeButton setHidden:YES];
        } break;
        default:
            break;
    }
    
    [self.priceLabel setText:model.creduce];
    [self.describeCountLabel setText:model.ctitle];
    [self.describePriceLabel setText:[NSString stringWithFormat:@"满%@元可用",model.cfull]];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    //[self.exchangeButton setGradientHorizontal:nil];
    [self.exchangeButton setGradient:nil startP:CGPointMake(0, 0) endP:CGPointMake(1, 0) bgView:nil];
    switch (_type) {
        case 0: case 1:
        {
            //[self.GradientView setGradientDiagonal:nil];
            [self.GradientView setGradient:nil startP:CGPointMake(0, 0) endP:CGPointMake(1, 1) bgView:nil];
        } break;
        case 2:
        {
            //[self.GradientView setGradientDiagonal:@[[UIColor colorWithHex:0xC0C0C0 alpha:1]]];
            [self.GradientView setBackgroundColor:[UIColor colorWithHex:0xC0C0C0 alpha:1]];
        } break;
        default:
            break;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
